package com.dy.design_pattern_study.store_cashier_system.factory.impl;

import com.dy.design_pattern_study.store_cashier_system.factory.CashSuper;

/**
 * @CreateBy zhangdingyi
 * @Date 2023-03-07
 * @Content 返利收费子类
 */
public class CashReturn extends CashSuper {

    private double moneyCondition = 0.0;
    private double moneyReturn = 0.0;

    //初始化时必须要输入返利条件和返利值
    //moneyCondition = 200 返 moneyReturn = 100
    public CashReturn(String moneyCondition,String moneyReturn){
        this.moneyCondition = Double.valueOf(moneyCondition);
        this.moneyReturn = Double.valueOf(moneyReturn);
    }

    @Override
    public double acceptCash(double money) {
        double result = money;
        //若大于返利条件则需要减去返利值
        if (money >= moneyCondition){
            result = money - (money / this.moneyCondition) * this.moneyReturn;
        }

        return result;
    }
}
